package com.example.demo3;

import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/Login")
@RestController
public class LoginController {
    @RequestMapping("/login")
public Boolean login(String userName, String password, HttpSession session){
//        if(userName==null||userName==""||password==""||password==null){
//            return false;
//        }

        if(!StringUtils.hasLength(userName)||!StringUtils.hasLength(password)){
            return false;
        }
       if("admin".equals(userName)&&"admin".equals(password)){
           session.setAttribute("userName",userName);
           return true;
       }
        return false;
    }

    @RequestMapping("/getLogin")
    public String getLogin(HttpSession session){
        return (String) session.getAttribute("userName");
    }

}
